
package game.manager {
	import common.IRender;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.utils.Dictionary;
	
	import utils.Singleton;
	
	/**
	 * RendererManager
	 *
	 * @author chris
	 *
	 * Apr 13, 2013
	 */
	public class RendererManager extends Singleton {
		private var rendererObj:Sprite;
		private var renderersDic:Dictionary;
		
		public function RendererManager()
		{
			super();
			rendererObj = new Sprite();
			renderersDic = new Dictionary();
		}
		
		public static function get inst():RendererManager {
			return Singleton.getInstanceOrCreate(RendererManager) as RendererManager;
		}
		
		public function start():void {
			rendererObj.addEventListener(Event.ENTER_FRAME,onEnterframe);
		}
		
		public function stop():void {
			rendererObj.removeEventListener(Event.ENTER_FRAME,onEnterframe);
		}
		
		public function addItem(render:IRender):void {
			renderersDic[render] = render;
		}
		
		public function removeItem(render:IRender):void {
			if(renderersDic[render]) {
				delete renderersDic[render];
				render = null;
			}
		}
		
		private function onEnterframe(evt:Event):void {
			var render:* = undefined;
			for(render in renderersDic) {
				render.frameScript();
			}
//			trace("hello");
		}
	}
}